package com.unbox.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.util.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import com.unbox.admin.entity.Setting;
import com.unbox.admin.mapper.SettingMapper;
import com.unbox.admin.service.ISettingService;
import com.unbox.common.table.UnBoxPage;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * <p>
 * < 系统设置业务实现类
 * </p>
 *
 * @author 王振宇
 * @since 2021-04-23
 */
@Service
public class SettingServiceImpl extends ServiceImpl<SettingMapper, Setting> implements ISettingService {

    @Override
    public Setting get(Setting setting) {
        LambdaQueryWrapper<Setting> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (!ObjectUtils.isEmpty(setting.getSettingId())) {
            lambdaQueryWrapper.eq(Setting::getSettingId, setting.getSettingId());
        }
        if (!StringUtils.isEmpty(setting.getName())) {
            lambdaQueryWrapper.eq(Setting::getName, setting.getName());
        }
        if (!StringUtils.isEmpty(setting.getLogo())) {
            lambdaQueryWrapper.eq(Setting::getLogo, setting.getLogo());
        }
        if (!StringUtils.isEmpty(setting.getIsFull())) {
            lambdaQueryWrapper.eq(Setting::getIsFull, setting.getIsFull());
        }
        if (!StringUtils.isEmpty(setting.getIsLange())) {
            lambdaQueryWrapper.eq(Setting::getIsLange, setting.getIsLange());
        }
        if (!StringUtils.isEmpty(setting.getIsSubject())) {
            lambdaQueryWrapper.eq(Setting::getIsSubject, setting.getIsSubject());
        }
        if (!StringUtils.isEmpty(setting.getIsSearch())) {
            lambdaQueryWrapper.eq(Setting::getIsSearch, setting.getIsSearch());
        }
        if (!StringUtils.isEmpty(setting.getIsLog())) {
            lambdaQueryWrapper.eq(Setting::getIsLog, setting.getIsLog());
        }
        if (!StringUtils.isEmpty(setting.getIsFont())) {
            lambdaQueryWrapper.eq(Setting::getIsFont, setting.getIsFont());
        }
        if (!StringUtils.isEmpty(setting.getIsColor())) {
            lambdaQueryWrapper.eq(Setting::getIsColor, setting.getIsColor());
        }
        if (!ObjectUtils.isEmpty(setting.getCreateTime())) {
            lambdaQueryWrapper.eq(Setting::getCreateTime, setting.getCreateTime());
        }
       return super.getOne(lambdaQueryWrapper);
    }

    @Override
    public List<Setting> getList(Setting setting) {
        LambdaQueryWrapper<Setting> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (!ObjectUtils.isEmpty(setting.getSettingId())) {
            lambdaQueryWrapper.eq(Setting::getSettingId, setting.getSettingId());
        }
        if (!StringUtils.isEmpty(setting.getName())) {
            lambdaQueryWrapper.eq(Setting::getName, setting.getName());
        }
        if (!StringUtils.isEmpty(setting.getLogo())) {
            lambdaQueryWrapper.eq(Setting::getLogo, setting.getLogo());
        }
        if (!StringUtils.isEmpty(setting.getIsFull())) {
            lambdaQueryWrapper.eq(Setting::getIsFull, setting.getIsFull());
        }
        if (!StringUtils.isEmpty(setting.getIsLange())) {
            lambdaQueryWrapper.eq(Setting::getIsLange, setting.getIsLange());
        }
        if (!StringUtils.isEmpty(setting.getIsSubject())) {
            lambdaQueryWrapper.eq(Setting::getIsSubject, setting.getIsSubject());
        }
        if (!StringUtils.isEmpty(setting.getIsSearch())) {
            lambdaQueryWrapper.eq(Setting::getIsSearch, setting.getIsSearch());
        }
        if (!StringUtils.isEmpty(setting.getIsLog())) {
            lambdaQueryWrapper.eq(Setting::getIsLog, setting.getIsLog());
        }
        if (!StringUtils.isEmpty(setting.getIsFont())) {
            lambdaQueryWrapper.eq(Setting::getIsFont, setting.getIsFont());
        }
        if (!StringUtils.isEmpty(setting.getIsColor())) {
            lambdaQueryWrapper.eq(Setting::getIsColor, setting.getIsColor());
        }
        if (!ObjectUtils.isEmpty(setting.getCreateTime())) {
            lambdaQueryWrapper.eq(Setting::getCreateTime, setting.getCreateTime());
        }
        return super.list(lambdaQueryWrapper);
    }

    @Override
    public UnBoxPage<List<Setting>> getPageList(Setting setting, int pageNo, int pageSize) {
        LambdaQueryWrapper<Setting> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (!ObjectUtils.isEmpty(setting.getSettingId())) {
            lambdaQueryWrapper.eq(Setting::getSettingId, setting.getSettingId());
        }
        if (!StringUtils.isEmpty(setting.getName())) {
            lambdaQueryWrapper.eq(Setting::getName, setting.getName());
        }
        if (!StringUtils.isEmpty(setting.getLogo())) {
            lambdaQueryWrapper.eq(Setting::getLogo, setting.getLogo());
        }
        if (!StringUtils.isEmpty(setting.getIsFull())) {
            lambdaQueryWrapper.eq(Setting::getIsFull, setting.getIsFull());
        }
        if (!StringUtils.isEmpty(setting.getIsLange())) {
            lambdaQueryWrapper.eq(Setting::getIsLange, setting.getIsLange());
        }
        if (!StringUtils.isEmpty(setting.getIsSubject())) {
            lambdaQueryWrapper.eq(Setting::getIsSubject, setting.getIsSubject());
        }
        if (!StringUtils.isEmpty(setting.getIsSearch())) {
            lambdaQueryWrapper.eq(Setting::getIsSearch, setting.getIsSearch());
        }
        if (!StringUtils.isEmpty(setting.getIsLog())) {
            lambdaQueryWrapper.eq(Setting::getIsLog, setting.getIsLog());
        }
        if (!StringUtils.isEmpty(setting.getIsFont())) {
            lambdaQueryWrapper.eq(Setting::getIsFont, setting.getIsFont());
        }
        if (!StringUtils.isEmpty(setting.getIsColor())) {
            lambdaQueryWrapper.eq(Setting::getIsColor, setting.getIsColor());
        }
        if (!ObjectUtils.isEmpty(setting.getCreateTime())) {
            lambdaQueryWrapper.eq(Setting::getCreateTime, setting.getCreateTime());
        }
        Page<Setting> page = new Page<>(pageNo,pageSize);
        IPage<Setting> pageResult = this.baseMapper.selectPage(page, lambdaQueryWrapper);
        UnBoxPage<List<Setting>> unBoxPage = new UnBoxPage<>();
        unBoxPage.setPageNo(pageNo);
        unBoxPage.setPageSize(pageSize);
        unBoxPage.setSumPageCount(pageResult.getPages());
        unBoxPage.setSumDataCount(pageResult.getTotal());
        unBoxPage.setDatas(pageResult.getRecords());
        return unBoxPage;
    }

    @Override
    public List<Setting> getIdsList(List<Integer> ids) {
        LambdaQueryWrapper<Setting> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.in(Setting::getSettingId, ids);
        return super.list(lambdaQueryWrapper);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean save(Setting entity) {
        return super.save(entity);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean saveBatch(List<Setting> entityList) {
        return super.saveBatch(entityList);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean update(Setting setting) {
        LambdaQueryWrapper<Setting> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Setting::getSettingId, setting.getSettingId());
        return super.update(setting, lambdaQueryWrapper);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean updateBatchById(List<Setting> entityList) {
        return super.updateBatchById(entityList);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean remove(Setting setting) {
        LambdaQueryWrapper<Setting> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Setting::getSettingId, setting.getSettingId());
        return super.remove(lambdaQueryWrapper);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean removeByIds(List<Integer> idList) {
        return super.removeByIds(idList);
    }
}
